package com.hulk.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.hulk.model.UserInfo;
import com.hulk.service.IUserInfoService;
import com.hulk.service.UserService;

/**  
 * 创建时间：2015-1-28 下午1:17:27  
 * @author andy  
 * @version 2.2  
 */
@Controller
@RequestMapping("/user")
public class UserController {

	@Autowired
	private UserService userService;
	
	@Autowired
	private IUserInfoService userInfoService;
	
	@RequestMapping("/showInfo/{userId}")
	public String showUserInfo(ModelMap modelMap, @PathVariable int userId){
		UserInfo userInfo = userService.getUserById(userId);
		modelMap.addAttribute("userInfo", userInfo);
		return "/user/showInfo";
	}
	
	@RequestMapping("/showInfos")
	public @ResponseBody Object showUserInfos(){
		List<Map<String,Object>> userInfos = userService.getUsers();
		return userInfos;
	}
	
	@RequestMapping("/insertUserInfo")
	public @ResponseBody Object insertUserInfo(@RequestBody @ModelAttribute UserInfo userInfo){
		System.out.println(userInfo);
		try {
			userService.insertUserInfo(userInfo);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return userInfo;
	}

	@RequestMapping("/testJson/{json}")
	public @ResponseBody Object testJson(@PathVariable String json){
		return json;
	}

	@RequestMapping("/testJson2/{json}")
	public @ResponseBody Object testJson2(@PathVariable JSONObject json){
		return json;
	}
	
	public void st(){
	}
}
